# Build recipe for fittsen (fork of fittstool).
#
# Copyright (c) 2018 Markus Tornow, <tornow@riseup.net>.
# Copyright (c) 2018-2019 Matias Fonzo, <selk@dragora.org>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

program=fittsen
version=20190618_277dd4f
release=4

# Set 'outdir' for a nice and well-organized output directory
outdir="${outdir}/${arch}/community/x-apps"

tarname=${program}-${version}.tar.lz

# Remote source(s)
fetch="
  http://rsync.dragora.org/current/sources/$tarname
  http://mirror.cedia.org.ec/dragora/current/sources/$tarname
"

description="
A mouse command utitlity.

Utility to bind commands to mouse button events on the screen corners,
via a simple and concise configuration file.
"

homepage=http://notabug.org/frusen/fittsen
license="GPLv2+ | New BSD (inih library)"

# Source documentation
docs="LICENSE* README.md github.README.md"
docsdir="${docdir}/${program}-${version}"

build()
{
    set -e

    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    make -j${jobs} CFLAGS="$QICFLAGS"

    mkdir -p "${destdir}/usr/bin"
    cp -p fittsen "${destdir}/usr/bin"/
    chmod 755 "${destdir}/usr/bin/fittsen"
    strip --strip-unneeded "${destdir}/usr/bin/fittsen"

    # Make symlink for compatibility with fittstool
    ( cd "${destdir}/usr/bin" && ln -sf fittsen fittstool )

    # Compress and link man pages (if needed)
    if test -d "${destdir}/$mandir"
    then
        (
            cd "${destdir}/$mandir"
            find . -type f -exec lzip -9 '{}' +
            find . -type l | while read -r file
            do
                ln -sf "$(readlink -- "$file").lz" "${file}.lz"
                rm -- "$file"
            done
        )
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"
    cp -p $docs "${destdir}${docsdir}/"
}

